package shiyaner;

public class Course {
	private String courseName;
	private int courseId; 
	private Teacher teacher;
	private Student[] students;
	private String time;
	private String room;

// 初始化一门课程
	public Course(int courseId, String courseName, Teacher teacher, String time, String room) {
		super();
		this.courseName = courseName;
		this.courseId = courseId;
		this.teacher = teacher;
		teacher.setCourse(this);
		this.students = new Student[60];  //设置选课人数上限
		this.time = time;
		this.room = room;
	}

	
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	
	public int getCourseId() {
		return courseId;
	}
	public void setCourseId(int courseId) {
		this.courseId = courseId;
	}
	
	
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	
	public Student[] getStudents() {
		return students;
	}
	public void setStudents(Student[] students) {
		this.students = students;
	}
	

	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}	


	public String getRoom() {
		return room;
	}
	public void setRoom(String room) {
		this.room = room;
	}


	public boolean addStudent(Student stu) {
		for (int i = 0; i < students.length; i++) {
			if (students[i] == null) {
				students[i] = stu;
				return true;
			}
		}
		return false;
	}


	public boolean rmStudent(Student stu) {
		for (int i = 0; i < students.length; i++) {
			if (students[i] == stu) {
				students[i] = null;
				return true;
			}
		}
		return false;
	}


	public String toString() {
		return "课程信息 {" + 
				"课程编号:" + courseId + 
				"，课程名称:'" + courseName + '\'' + 
				"，所在教室:'" + room + '\''+ 
				"，上课时间:'" + time + '\'' + 
				"，授课教师:'" + teacher+ '\'' + "}\n";
	}
}